#! /bin/sh
. /etc/utils.sh

case "$1" in
  start|"")
    if interface_exists wan0; then
      babysit 60 netusage -i wan0 2>&1 | logos netusage &
    fi
    suitable=1
    if is-network-box || is-storage-box || is-tv-box; then
      suitable=0
    fi
    if [ $suitable -eq 0 ] && runnable dhcp-rogue && interface_exists br0; then
      babysit 60 run-dhcp-rogue | logos dhcprogue &
    fi
    ;;
  stop)
    pkillwait netusage
    pkillwait -f dhcp-rogue
    ;;
  restart)
    $0 stop; $0 start
    ;;
  *)
    echo "Usage: netmon {start|stop|restart}" >&2
    exit 1
    ;;
esac
